<template>

	<view>
		<!-- #ifdef MP-WEIXIN -->
		<official-account></official-account>
		<!-- #endif -->
		<view class="card">
			<text style="font-size: 16px;color: #333;font-weight: 600;margin-bottom: 13px;">{{title}}</text>
			<view class="">
				{{auth}}
			</view>
			 
				<image :src="img" mode="aspectFill" v-if="img"></image>
		 
			<mp-html :content="fillText(content)"></mp-html>
		</view>
		<view class="card">
			<mp-html :content="s_rich"></mp-html>
		</view>
	</view>
</template>

<script>
	import Request from '@/utils/luch-request/index.js'
	const http = new Request();
	import {
		domain,
		pluginapi,

	} from '@/utils/api.js';

	var wv; //计划创建的webview
	export default {

		data() {
			return {
				domain: domain,
				url: '',
				content: '',
				s_rich: '',
				img: '',
				auth: '',
				frontColor: '',
				backgroundColor: '',
				weburl: '',
				title: '',
				sharetitle: '',
				webviewStyles: {
					progress: false //必须要设置为false

				}
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			// console.log('分享页面options', options)
			// console.log('分享页面options.url', options.content)

			if (options.from === 'pyq') { // 详情页二次跳转

				let url = '/pages/webview/webview?url=' + decodeURIComponent(options.url);
				console.log('navigateTourl', url)
				uni.navigateTo({
					url: url
				})
			}
			this.getData(options);
			this.content = options.content;
			this.weburl = options.url;
			this.title = options.title;
			this.auth = options.auth;
			this.img = options.img;
		},
		onReady() {



		},
		onShow() {

		},
		onBackPress(e) {
			let pages = getCurrentPages()
			let page = pages[pages.length - 1];
			let currentPages = page.$getAppWebview()
			currentPages.close()
			return false

		},
		onNavigationBarButtonTap(e) {
			var index = e.index;
			if (e.index == 0) {
				var pathvalue = '/pages/webview/webview?url=' + encodeURIComponent(myurl);
				uni.navigateTo({
					url: pathvalue
				})


			};

			if (e.index == 1) {
				var homeurl = getApp().globalData.url;
				var pathvalue = '/pages/webview/webview?url=' + encodeURIComponent(domain);
				uni.navigateTo({
					url: pathvalue
				})

			}

		},

		onShareAppMessage: function(options) {
			// console.log('options??', options)
			// console.log('path??', this.weburl)
			var that = this;
			// 设置菜单中的转发按钮触发转发事件时的转发内容
			var shareObj = {
				title: this.title,
				path: '/pages/share/share?from=pyq&url=' + encodeURIComponent(this.weburl),

			};

			// 返回shareObj
			return shareObj;
		},

		onShareTimeline: function(options) {
			// console.log('path??', this.weburl)
			return {
				title: this.title,
				query: "from=pyq&url=" + encodeURIComponent(this.weburl) +'&title='+this.title + '&content='+this.content +'&auth='+this.auth+'&img='+this.img,
				imageUrl: this.img ? this.img : this.logo,
			}
		},

		methods: {

			fillText(t) {

				return t.replace(/\\n/g, "")
			},


			getData: function(options) {
				http.get(pluginapi).then(res => {
					this.s_rich = res.data.s_rich;
					this.logo = res.data.logo;
					this.navtitle = res.data.s_title;
					this.frontColor = res.data.frcolor;
					this.backgroundColor = res.data.bgcolor;
					uni.setNavigationBarColor({
						frontColor: this.frontColor,
						backgroundColor: this.backgroundColor,

					})
					// console.log('this.navtitle', this.navtitle)
					uni.setNavigationBarTitle({
						title: this.navtitle
					})


				}).catch(err => {

				})

			},



		},



	};
</script>
<style lang="scss">
	page {
		background-color: #f7f7f7;
	}

	.card {
		margin: 13px;
		padding: 12px;
		background-color: #ffffff;
		border-radius: 12rpx;
	}
	.card image{
		 width: 100%;
		border-radius: 12rpx;
	}
</style>
